package com.hadron.transitions.behaviors.lib 
{
	import com.greensock.easing.*;
	import com.greensock.TweenLite;
	import com.hadron.transitions.behaviors.TransitionBehavior;
	import com.hadron.transitions.enum.TransitionType;
	import temple.utils.types.ArrayUtils;

	/**
	 * TB_Move
	 * @author Hadron
	 * date created: 05-28-2011
	 */
	public class TB_Move extends TransitionBehavior 
	{
		///////////////////////////
		// FIELDS
		///////////////////////////
		private var _fadeInTime:Number = 2;
		private var _endX:Number;
		private var _endY:Number;
		private var _startX:Number;
		private var _startY:Number;
		private var _moveAreaWidth:Number = 690;
		private var _moveAreaHeight:Number = 370;
		private var transitions:Array = [ 
			TransitionType.BOTTOM_RIGHT_TOP_LEFT,
			TransitionType.BOTTOM_LEFT_TOP_RIGHT,
			TransitionType.TOP_LEFT_BOTTOM_RIGHT,
			TransitionType.TOP_RIGHT_BOTTOM_LEFT
		];
		/**
		  * This method constructs instance of this class
		 */
		public function TB_Move(target:Object) 
		{
			super(target);
		}
		/*------------------- PUBLIC METHODS -------------------*/
		override public function transitionIn():void
		{
			if (_enabled)
			{
				setPositions(); // object must be added to stage in order to set parent width /height
				targetObject.alpha = 0;
				targetObject.x = _startX;
				targetObject.y = _startY;
				TweenLite.to(target, fadeInTime,
						   { alpha:1,
							x:_endX,
							y:_endY,
						     ease:Linear.easeNone,
							onComplete:targetObject.transitionInComplete } );
			} else {
				targetObject.transitionInComplete();
				enable();
			}
		}
		
		private function setPositions():void 
		{
			switch(type)
			{
				case TransitionType.BOTTOM_LEFT_TOP_RIGHT:
					_startX = 0;
					_startY = _moveAreaHeight - targetObject.height;
					_endX =  _moveAreaWidth - targetObject.width;
					_endY = 0;
				break;
				
				case TransitionType.BOTTOM_RIGHT_TOP_LEFT:
					_startX = _moveAreaWidth - targetObject.width;
					_startY = _moveAreaHeight - targetObject.height;
					_endX =  0;
					_endY = 0;
				break;
				
				case TransitionType.TOP_LEFT_BOTTOM_RIGHT:
					_startX = 0;
					_startY = 0;
					_endX =  _moveAreaWidth - targetObject.width;
					_endY = _moveAreaHeight - targetObject.height;
				break;
				
				case TransitionType.TOP_RIGHT_BOTTOM_LEFT:
					_startX = _moveAreaWidth - targetObject.width;
					_startY = 0;
					_endX =  0;
					_endY = _moveAreaHeight - targetObject.height;
				break;
				
				case TransitionType.RANDOM:
					type = ArrayUtils.randomElement(transitions);
					setPositions();
				break;
			}
		}
		
		/*------------------ GETTERS & SETTERS -----------------*/
		public function get fadeInTime():Number { return _fadeInTime; }
		public function set fadeInTime(value:Number):void { _fadeInTime = value; }
		
		override public function set vars(value:Object):void
		{
			super.vars = value;
			if (vars.fadeInTime != undefined)
				fadeInTime = vars.fadeInTime;
		}
		
		/*------------------- PRIVATE METHODS ------------------*/
		
		
		/*------------------- EVENT HANDLERS --------------------*/
	}
}